package com.huangjue.backend.config;

import com.huangjue.backend.job.MyJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail jobDetail() {

        return JobBuilder.newJob(MyJob.class)
                .storeDurably()//持久化
                .withIdentity("定时让智能体进行讨论","group1")
                .usingJobData("croExpression","0 30 0 * * ?")//共享数据的初始化
                .build();
    }

    @Bean
    public Trigger trigger() {
//        String croExpression = "0 30 0 * * ?";//每天晚上的十二点半（00:30）执行
//        String croExpression = "0 */1 * * * ?"; // 每1分钟执行一次
        String croExpression = "0 */5 * * * ?"; // 每10分钟执行一次
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withSchedule(CronScheduleBuilder.cronSchedule(croExpression)) //时间规则，cron表达式
                .withIdentity("Trigger1","group1")//唯一标识
                .build();
    }
}
